package com.spring.boot.quartz.service.impl;

import com.spring.boot.quartz.service.EncapsulationQuartzService;
import com.spring.boot.quartz.service.QuartzService;
import org.custom.spring.boot.useless.QuartzJob;
import org.quartz.JobKey;
import org.quartz.SchedulerException;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 封装QuartzServiceImpl
 *
 * @author LiKun
 * @date 2021/7/31 14:02
 */
@Service("encapsulationQuartzService")
public class EncapsulationQuartzServiceImpl implements EncapsulationQuartzService {
    @Resource
    private QuartzService quartzService;
    @Resource
    private Map<String, QuartzJobBean> jobInit;

    @Override
    public void deleteJob(QuartzJob job) throws SchedulerException {
        quartzService.deleteJob(new JobKey(job.getName(), job.getGroup()));
    }

    @Override
    public void addJob(QuartzJob job) throws SchedulerException {
        quartzService.addJob(jobInit.get(job.getJob()).getClass(),
                job.getName(), job.getGroup(), job.getCorn(), job.getStartTime(), job.getJobData());
    }

    @Override
    public void updateJob(QuartzJob job) throws SchedulerException {
        quartzService.updateJob(jobInit.get(job.getJob()).getClass(),
                job.getName(), job.getGroup(), job.getCorn(), job.getStartTime(), job.getJobData());
    }
}
